﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Agility.Extensions.DatabaseAccessor.EntityFrameworkCore;
using Microsoft.AspNetCore.Mvc;
using OpenAdmin.Application.Services;
using OpenAdmin.Application.Services.Dtos;

namespace OpenAdmin.HttpApi.Controllers;

/// <summary>
/// 功能操作接口相关Api
/// </summary>
[ApiExplorerSettings(GroupName = "Application")]
public class OperationController : ApiControllerBase
{
    private readonly IOperationService _operationServices;
    /// <summary>
    /// 构造函数
    /// </summary>
    public OperationController(IOperationService operationServices)
    {
        _operationServices = operationServices;
    }

    /// <summary>
    /// 获取功能操作功能
    /// </summary>
    /// <returns></returns>
    [HttpGet, ProducesResponseType(typeof(List<OperationResponseDto>), 200)]
    public async Task<IActionResult> GetOperationsByMenuId(int menuId)
    {
        return Ok(await _operationServices.GetOperationsByMenuId(menuId));
    }

    /// <summary>
    /// 添加功能操作功能
    /// </summary>
    /// <param name="requestDto"></param>
    /// <returns></returns>
    [HttpPost, UnitOfWork]
    public async Task<IActionResult> AddOperation(AddOperationRequestDto requestDto)
    {
        await _operationServices.AddOperation(requestDto);

        return Ok();
    }

    /// <summary>
    /// 编辑功能操作功能
    /// </summary>
    /// <param name="requestDto"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<IActionResult> EditOperation(EditOperationRequestDto requestDto)
    {
        await _operationServices.EditOperation(requestDto);

        return Ok();
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<IActionResult> DeleteOperation(int id)
    {
        await _operationServices.DeleteOperation(id);

        return Ok();
    }
}
